// /*
//  * @Author: WanYiMing
//  * @Date:2024-07-26-10:31
//  * @Description:
//  */

using System;
using UnityEngine;

namespace Code.Monster
{
    public class SpaceLine : MonoBehaviour
    {
        [SerializeField]
        public float radius = 5f;
        [SerializeField]
        public int segments = 100;
        [SerializeField]
        private LineRenderer line;
        [SerializeField]
        public bool isShow = true;
        
        
        void Start()
        {
          
        }

        public void Draw(float tradius)
        {   
            if(!isShow)return;
            line = gameObject.GetComponent<LineRenderer>();
            line.positionCount = segments + 1;
            line.useWorldSpace = false;
            line.sortingOrder = 2;
            radius = tradius;   
            float x;
            float y;
            float z = 0f;

            float angle = 20f;

            for(int i = 0; i < segments + 1; i++)
            {
                x = Mathf.Sin(Mathf.Deg2Rad * angle) * radius;
                y = Mathf.Cos(Mathf.Deg2Rad * angle) * radius;

                line.SetPosition(i, new Vector3(x, y, z));

                angle += (360f / segments);
            }
        }
        
    }
}